<?php 
 
class OneToMany extends fpp_tdp_Model{

  private $secondM = null;

  function __construct($DataObjects){
    parent::__construct($DataObjects);
  }

  public function __toString(){
    $Model =  $this->args->model.'_Model';
    $Model = new $Model;
    $firstM = $this->attributes->NameModel;
    $metaModel = $Model->Get_Meta();
    foreach($metaModel as $field => $ref){
      $ModelIn = explode("(model=",$ref);
//       echo Kohana::debug($ModelIn);
      if(count($ModelIn) > 1){
        $ComNameMod = substr($ModelIn[1],0,-1)."_Model";
        if(!($ComNameMod == $this->attributes->NameModel)){
          $this->secondM = substr($ModelIn[1],4,-1);
        }
      }
    }
    
    return $this->_DropDown();
  }
  
  private function _DropDown(){
    /* Construyendo el Query */    
    $Model =  "fpp_".$this->secondM.'_Model';
    $Model = new $Model;
    $select[] = $Model->_FirstPrimary .' as value ';
    $select[] = $this->args->db_label.' as label ';
    $this->args->db_table = $this->secondM; //compatibilidad para obtener el Link AJAX fpp_tdp #34
    $one_to_one=$this->db->from($this->secondM)->select($select)->get();
    /* Construyendo el Array del Dropdown */
    foreach($one_to_one as $row){
      $drop[$row->value] = $row->label;
    }
     $html = $this->AjaxConstruct(form::dropdown($this->field_name.'[]',@$drop,$this->field_value,
              ' multiple="multiple" '));
     return $html;
  }
}

?>